package com.zkw.controller;

import com.zkw.domain.Book;
import com.zkw.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BookController {
    @Autowired
    private BookService bookService;

    @GetMapping("/get/{id}")
    public Book findById(@PathVariable int id){
        Book book = bookService.findById(id);
        return book;
    }

    @GetMapping("/getapi/{id}")
    public Book findByIdAPI(@PathVariable int id){
        Book book = bookService.findByIdAPI(id);
        return book;
    }

    @GetMapping("/update/{id}/{description}")
    public Book updateBook(@PathVariable String description, @PathVariable Integer id){
        Book book = bookService.findById(id);
        book.setDescription(description);
        Book result = bookService.updateBook(book);
        return result;
    }

    @GetMapping("/delete/{id}")
    public void deleteBook(@PathVariable int id){
        bookService.deleteBook(id);
    }
}
